using System;
using System.Collections.Generic;

namespace Astro.Core
{
	[Serializable]
    public class CommentTypeSettings
	{
        public static readonly string defaultName = "Default::Comment::Types";

        string _name = "Comment Type Items";
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public List<CommentTypeItem> Items { get; set; }

        public void Add(CommentTypeItem item)
        {
            if (item.Id == Guid.Empty)
                item.Id = Guid.NewGuid();

            if (Items == null)
                Items = new List<CommentTypeItem>();

            Items.Add(item);
        }

        public bool HasItems
        {
            get { return Items != null && Items.Count > 0; }
        }

        public static CommentTypeSettings Get()
        {
            CommentTypeSettings cts = ObjectManager.Get<CommentTypeSettings>(defaultName);

            return cts;
        }

        public static string GetContentTypeIdByName(string name)
        {
            string result = "";

            CommentTypeItem temp = Get().Items.Find(delegate(CommentTypeItem cf)
            {
                return cf.Name.ToLower().Equals(name.ToLower());

            });

            if (temp != null)
                result = temp.Id.ToString();

            return result;
        }

        public void Save()
        {
            if (string.IsNullOrEmpty(Name))
                throw new Exception("The name of the comment type cannot be null");

            ObjectManager.Save(this, defaultName);
        }
	}

    public class CommentTypeItem
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }
}